package mylab.commons.web.mvc.impl;


import mylab.base.model.entity.Entity;
import mylab.commons.web.mvc.controller.BaseController;
import mylab.starters.mybatis.template.SuperService;
import mylab.utils.common.ReflectUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;

public abstract class BaseControllerImpl<
        K extends Serializable,
        E extends Entity<K>,
        S extends SuperService<K, E>>
        implements BaseController<K, E, S> {

    @Autowired
    protected S service;
    protected Class<E> entityClass = null;

    @Override
    public Class<E> getEntityClass() {
        if (entityClass == null) {
            this.entityClass = ReflectUtil.getGenericType(this.getClass(), 1);
        }
        return entityClass;
    }

    @Override
    public S getService() {
        return service;
    }
}
